home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1999 / MacHack 1999.toast / The Hacks / X-Ray / X-Ray INIT Source / windowPatches.c < prev    next >
Encoding:
Text File  |  1999-06-17  |  44.5 KB  |  1,425 lines  |  [TEXT/CWIE]

  1. // Copyright (C) 1999 Eric Roccasecca.  All rights reserved.
  2.  
  3. #include "X_Ray_Priv.h"
  4. #include "Layers.h"
  5.  
  6. UniversalProcPtr    gOldMoveWindow, gMoveWindowUPP,
  7.                     gOldCloseWindow, gCloseWindowUPP,
  8.                     gOldSizeWindow, gSizeWindowUPP,
  9.                     gOldHideWindow, gHideWindowUPP,
  10.                     gOldShowWindow, gShowWindowUPP,
  11.                     gOldShowHide, gShowHideUPP,
  12.                     gOldBringToFront, gBringToFrontUPP,
  13.                     gOldZoomWindow, gZoomWindowUPP,
  14.                     gOldSendBehind, gSendBehindUPP,
  15.                     gOldFindWindow, gFindWindowUPP,
  16.                     gOldSelectWindow, gSelectWindowUPP,
  17.                     gOldDragWindow, gDragWindowUPP,
  18.                     gOldGrowWindow, gGrowWindowUPP,
  19.                     
  20.                     gOldDragGrayRgn, gDragGrayRgnUPP,
  21.                     gInitWindowsUPP,
  22.                     gOldNewWindow, gNewWindowUPP,
  23.                     gOldNewCWindow, gNewCWindowUPP,
  24.                     gOldGetNewWindow, gGetNewWindowUPP,
  25.                     gOldGetNewCWindow, gGetNewCWindowUPP;
  26.                     
  27. Boolean                gProcessManagerIsRunning;
  28.  
  29. // window manager specific globals
  30. GrafPtr                wm_curPort;
  31. CGrafPtr            wm_origGWorld;
  32. GDHandle            wm_origGDH;
  33. RgnHandle            wm_transReorderVisRgn, wm_transVisRgn, wm_visRgn, wm_findWindowVisRgn, wm_strucRgn, wm_transStrucRgn, wm_origStrucRgn;
  34. X_Ray_WindowHandle    wm_transWindow, wm_intersection, wm_curIntersection, wm_tempWin;
  35. X_Ray_AppRecHandle    wm_curApp;
  36. short                wm_workLevel = 0;
  37. WindowPtr            wm_curWindow;
  38.  
  39.  
  40. extern    short        X_RayDrawLevel;
  41.  
  42. // Patches
  43. pascal void X_Ray_MoveWindow (WindowPtr theWindow, short hGlobal, short vGlobal, Boolean front);
  44. pascal void X_Ray_CloseWindow (WindowPtr theWindow);
  45. pascal void X_Ray_SizeWindow (WindowPtr theWindow, short w, short h, Boolean fUpdate);
  46. pascal long X_Ray_GrowWindow (WindowPtr theWindow, Point startPt, const Rect *bBox);
  47. pascal void X_Ray_HideWindow (WindowPtr theWindow);
  48. pascal void X_Ray_ShowWindow (WindowPtr theWindow);
  49. pascal void X_Ray_BringToFront (WindowPtr theWindow);
  50. pascal void X_Ray_SelectWindow (WindowPtr theWindow);
  51. pascal void X_Ray_DragWindow (WindowPtr theWindow, Point startPt, const Rect *boundsRect);
  52. pascal void X_Ray_ShowHide (WindowPtr theWindow, Boolean showFlag);
  53. pascal void X_Ray_ZoomWindow (WindowPtr theWindow, short partCode, Boolean front);
  54. pascal void X_Ray_SendBehind (WindowPtr theWindow, WindowPtr behindWindow);
  55. pascal short X_Ray_FindWindow (Point thePoint, WindowPtr *theWindow);
  56.  
  57. pascal long X_Ray_DragGrayRgn (RgnHandle theRgn, Point startPt, const Rect *limitRect, const Rect *slopRect, short axis, DragGrayRgnProcPtr actionProc);
  58. pascal void X_Ray_InitWindows (void);
  59.  
  60. pascal WindowPtr X_Ray_NewWindow (void *wStorage, const Rect *boundsRect, ConstStr255Param title, Boolean visible, short theProc, WindowPtr behind, Boolean goAwayFlag, long refCon);
  61. pascal WindowPtr X_Ray_NewCWindow (void *wStorage, const Rect *boundsRect, ConstStr255Param title, Boolean visible, short theProc, WindowPtr behind, Boolean goAwayFlag, long refCon);
  62. pascal WindowPtr X_Ray_GetNewWindow (short windowID, void *wStorage, WindowPtr behind);
  63. pascal WindowPtr X_Ray_GetNewCWindow (short windowID, void *wStorage, WindowPtr behind);
  64.  
  65. void PaintBehindTransparent (void);
  66. void PaintBehindOnSwitch (LayerPtr appGlobalWindow);
  67.  
  68. Boolean SetupSecretStuff (void);
  69.  
  70. void ConfirmRgn (RgnHandle theRgn);
  71.  
  72.  
  73. Boolean InitInternalWindowManager ()
  74. {
  75.     wm_transVisRgn = NewRgn();
  76.     wm_visRgn = NewRgn();
  77.     wm_findWindowVisRgn = NewRgn();
  78.     wm_strucRgn = NewRgn();
  79.     wm_transStrucRgn = NewRgn();
  80.     wm_origStrucRgn = NewRgn();
  81.     wm_transReorderVisRgn = NewRgn();
  82.     
  83.     // WINDOW MANAGER PATCHES
  84.     
  85.     // Apply patch to NewWindow
  86.     /*
  87.     gOldNewWindow = NGetTrapAddress (_NewWindow, ToolTrap);
  88.     gNewWindowUPP = NewRoutineDescriptor ((ProcPtr)X_Ray_NewWindow, kNewWindowProcInfo, kPowerPCISA);
  89.     if (gNewWindowUPP)
  90.         NSetTrapAddress (gNewWindowUPP, _NewWindow, ToolTrap);
  91.     else
  92.         return false;
  93.     
  94.     // Apply patch to NewCWindow
  95.     gOldNewCWindow = NGetTrapAddress (_NewCWindow, ToolTrap);
  96.     gNewCWindowUPP = NewRoutineDescriptor ((ProcPtr)X_Ray_NewCWindow, kNewWindowProcInfo, kPowerPCISA);
  97.     if (gNewCWindowUPP)
  98.         NSetTrapAddress (gNewCWindowUPP, _NewCWindow, ToolTrap);
  99.     else
  100.         return false;
  101.     
  102.     // Apply patch to GetNewWindow
  103.     gOldGetNewWindow = NGetTrapAddress (_GetNewWindow, ToolTrap);
  104.     gGetNewWindowUPP = NewRoutineDescriptor ((ProcPtr)X_Ray_GetNewWindow, kGetNewWindowProcInfo, kPowerPCISA);
  105.     if (gGetNewWindowUPP)
  106.         NSetTrapAddress (gGetNewWindowUPP, _GetNewWindow, ToolTrap);
  107.     else
  108.         return false;
  109.     
  110.     // Apply patch to GetNewCWindow
  111.     gOldGetNewCWindow = NGetTrapAddress (_GetNewCWindow, ToolTrap);
  112.     gGetNewCWindowUPP = NewRoutineDescriptor ((ProcPtr)X_Ray_GetNewCWindow, kGetNewWindowProcInfo, kPowerPCISA);
  113.     if (gGetNewCWindowUPP)
  114.         NSetTrapAddress (gGetNewCWindowUPP, _GetNewCWindow, ToolTrap);
  115.     else
  116.         return false;
  117.     */
  118.     
  119.     // Make routine descriptor for InitWindows for local patches
  120.     gInitWindowsUPP = NewRoutineDescriptor ((ProcPtr)X_Ray_InitWindows, kInitWindowsProcInfo, GetCurrentArchitecture());
  121.     gProcessManagerIsRunning = false; // a helper flag
  122.     
  123.     // Apply patch to MoveWindow
  124.     gOldMoveWindow = NGetTrapAddress (_MoveWindow, ToolTrap);
  125.     gMoveWindowUPP = NewRoutineDescriptor ((ProcPtr)X_Ray_MoveWindow, kMoveWindowProcInfo, kPowerPCISA);
  126.     if (gMoveWindowUPP)
  127.         NSetTrapAddress (gMoveWindowUPP, _MoveWindow, ToolTrap);
  128.     else
  129.         return false;
  130.     
  131.     // Apply patch to CloseWindow
  132.     gOldCloseWindow = NGetTrapAddress (_CloseWindow, ToolTrap);
  133.     gCloseWindowUPP = NewRoutineDescriptor ((ProcPtr)X_Ray_CloseWindow, kCloseWindowProcInfo, kPowerPCISA);
  134.     if (gCloseWindowUPP)
  135.         NSetTrapAddress (gCloseWindowUPP, _CloseWindow, ToolTrap);
  136.     else
  137.         return false;
  138.     
  139.     // Apply patch to SizeWindow
  140.     gOldSizeWindow = NGetTrapAddress (_SizeWindow, ToolTrap);
  141.     gSizeWindowUPP = NewRoutineDescriptor ((ProcPtr)X_Ray_SizeWindow, kSizeWindowProcInfo, kPowerPCISA);
  142.     if (gSizeWindowUPP)
  143.         NSetTrapAddress (gSizeWindowUPP, _SizeWindow, ToolTrap);
  144.     else
  145.         return false;
  146.     
  147.     // Apply patch to GrowWindow
  148.     gOldGrowWindow = NGetTrapAddress (_GrowWindow, ToolTrap);
  149.     gGrowWindowUPP = NewRoutineDescriptor ((ProcPtr)X_Ray_GrowWindow, kGrowWindowProcInfo, kPowerPCISA);
  150.     if (gGrowWindowUPP)
  151.         NSetTrapAddress (gGrowWindowUPP, _GrowWindow, ToolTrap);
  152.     else
  153.         return false;
  154.     
  155.     // Apply patch to HideWindow
  156.     gOldHideWindow = NGetTrapAddress (_HideWindow, ToolTrap);
  157.     gHideWindowUPP = NewRoutineDescriptor ((ProcPtr)X_Ray_HideWindow, kHideWindowProcInfo, kPowerPCISA);
  158.     if (gHideWindowUPP)
  159.         NSetTrapAddress (gHideWindowUPP, _HideWindow, ToolTrap);
  160.     else
  161.         return false;
  162.     
  163.     // Apply patch to ShowWindow
  164.     gOldShowWindow = NGetTrapAddress (_ShowWindow, ToolTrap);
  165.     gShowWindowUPP = NewRoutineDescriptor ((ProcPtr)X_Ray_ShowWindow, kShowWindowProcInfo, kPowerPCISA);
  166.     if (gShowWindowUPP)
  167.         NSetTrapAddress (gShowWindowUPP, _ShowWindow, ToolTrap);
  168.     else
  169.         return false;
  170.     
  171.     // Apply patch to ShowHide
  172.     gOldShowHide = NGetTrapAddress (_ShowHide, ToolTrap);
  173.     gShowHideUPP = NewRoutineDescriptor ((ProcPtr)X_Ray_ShowHide, kShowHideProcInfo, kPowerPCISA);
  174.     if (gShowHideUPP)
  175.         NSetTrapAddress (gShowHideUPP, _ShowHide, ToolTrap);
  176.     else
  177.         return false;
  178.     
  179.     // Apply patch to BringToFront
  180.     gOldBringToFront = NGetTrapAddress (_BringToFront, ToolTrap);
  181.     gBringToFrontUPP = NewRoutineDescriptor ((ProcPtr)X_Ray_BringToFront, kBringToFrontProcInfo, kPowerPCISA);
  182.     if (gBringToFrontUPP)
  183.         NSetTrapAddress (gBringToFrontUPP, _BringToFront, ToolTrap);
  184.     else
  185.         return false;
  186.     
  187.     // Apply patch to SelectWindow
  188.     gOldSelectWindow = NGetTrapAddress (_SelectWindow, ToolTrap);
  189.     gSelectWindowUPP = NewRoutineDescriptor ((ProcPtr)X_Ray_SelectWindow, kSelectWindowProcInfo, kPowerPCISA);
  190.     if (gSelectWindowUPP)
  191.         NSetTrapAddress (gSelectWindowUPP, _SelectWindow, ToolTrap);
  192.     else
  193.         return false;
  194.     
  195.     // Apply patch to DragWindow
  196.     gOldDragWindow = NGetTrapAddress (_DragWindow, ToolTrap);
  197.     gDragWindowUPP = NewRoutineDescriptor ((ProcPtr)X_Ray_DragWindow, kDragWindowProcInfo, kPowerPCISA);
  198.     if (gDragWindowUPP)
  199.         NSetTrapAddress (gDragWindowUPP, _DragWindow, ToolTrap);
  200.     else
  201.         return false;
  202.     
  203.     // Apply patch to ZoomWindow
  204.     gOldZoomWindow = NGetTrapAddress (_ZoomWindow, ToolTrap);
  205.     gZoomWindowUPP = NewRoutineDescriptor ((ProcPtr)X_Ray_ZoomWindow, kZoomWindowProcInfo, kPowerPCISA);
  206.     if (gZoomWindowUPP)
  207.         NSetTrapAddress (gZoomWindowUPP, _ZoomWindow, ToolTrap);
  208.     else
  209.         return false;
  210.     
  211.     // Apply patch to SendBehind
  212.     gOldSendBehind = NGetTrapAddress (_SendBehind, ToolTrap);
  213.     gSendBehindUPP = NewRoutineDescriptor ((ProcPtr)X_Ray_SendBehind, kSendBehindProcInfo, kPowerPCISA);
  214.     if (gSendBehindUPP)
  215.         NSetTrapAddress (gSendBehindUPP, _SendBehind, ToolTrap);
  216.     else
  217.         return false;
  218.     
  219.     // Apply patch to FindWindow
  220.     gOldFindWindow = NGetTrapAddress (_FindWindow, ToolTrap);
  221.     gFindWindowUPP = NewRoutineDescriptor ((ProcPtr)X_Ray_FindWindow, kFindWindowProcInfo, kPowerPCISA);
  222.     if (gFindWindowUPP)
  223.         NSetTrapAddress (gFindWindowUPP, _FindWindow, ToolTrap);
  224.     else
  225.         return false;
  226.     
  227.     // Apply patch to DragGrayRgn
  228.     gOldDragGrayRgn = NGetTrapAddress (_DragGrayRgn, ToolTrap);
  229.     gDragGrayRgnUPP = NewRoutineDescriptor ((ProcPtr)X_Ray_DragGrayRgn, kDragGrayRgnProcInfo, kPowerPCISA);
  230.     if (gDragGrayRgnUPP)
  231.         NSetTrapAddress (gDragGrayRgnUPP, _DragGrayRgn, ToolTrap);
  232.     else
  233.         return false;
  234.     
  235.     if (!SetupSecretStuff())
  236.         return false;
  237.     
  238.     X_Ray_BuildWDEF();
  239.     
  240.     return true;
  241. }
  242.  
  243.  
  244. pascal void X_Ray_MoveWindow (WindowPtr theWindow, short hGlobal, short vGlobal, Boolean front)
  245. {
  246.     RgnHandle    curVisRgn;
  247.     
  248.     if (wm_workLevel == 0)
  249.     {
  250.         wm_workLevel++;
  251.         GetPort (&wm_curPort);
  252.         
  253.         SetPort (theWindow); // to get proper graphics coordinates
  254.         CopyRgn (theWindow->visRgn, wm_visRgn);
  255.         X_Ray_LocalToGlobalRgn (wm_visRgn);
  256.         
  257.         wm_transWindow = X_Ray_GetWindowRec (theWindow);
  258.         wm_intersection = PortDoesIntersect (theWindow, wm_visRgn);
  259.         
  260.         if (wm_transWindow)
  261.         {
  262.             if (front)
  263.             {
  264.                 //DebugStr ("\pX_Ray_MoveWindow");
  265.                 ReorderWindow (wm_transWindow, kROMethod_MoveWindow, nil);
  266.             }
  267.             
  268.             // preserve old visRgn before window is moved
  269.             SetPort ((*wm_transWindow)->theWindow);
  270.             CopyRgn (((*wm_transWindow)->theWindow)->visRgn, wm_transVisRgn);
  271.             X_Ray_LocalToGlobalRgn (wm_transVisRgn);
  272.             SetPort (wm_curPort);
  273.             CopyRgn (((WindowPeek)((*wm_transWindow)->theWindow))->strucRgn, wm_transStrucRgn);
  274.         }
  275.         else
  276.             CopyRgn (((WindowPeek)theWindow)->strucRgn, wm_origStrucRgn);
  277.         
  278.         if (wm_intersection)
  279.         {            
  280.             // the moving window's visRgn does intersect at least one transWin
  281.             
  282.             curVisRgn = NewRgn();
  283.             
  284.             wm_curIntersection = wm_intersection;
  285.             while (wm_curIntersection) // walk forward through all trans wins to determine who all intersects
  286.             {
  287.                 SetPort ((*wm_curIntersection)->theWindow); // to get proper screen coordinates
  288.                 CopyRgn ((*wm_curIntersection)->theWindow->visRgn, curVisRgn);
  289.                 X_Ray_LocalToGlobalRgn (curVisRgn);
  290.                 SectRgn (wm_visRgn, curVisRgn, curVisRgn);
  291.                 SetPort (theWindow);
  292.                 X_Ray_GlobalToLocalRgn (curVisRgn);
  293.                 InvalRgn (curVisRgn);
  294.                 
  295.                 wm_tempWin = wm_curIntersection;
  296.                 wm_curIntersection = GetNextWindowAbove (wm_curIntersection);
  297.             }
  298.             
  299.             DisposeRgn (curVisRgn);
  300.             SetPort (wm_curPort);
  301.         }
  302.         
  303.         CallUniversalProc (gOldMoveWindow, kMoveWindowProcInfo, theWindow, hGlobal, vGlobal, front);
  304.         
  305.         AssureMovingWindowIsRefreshed (theWindow);
  306.         
  307.         if (wm_intersection)
  308.         {
  309.             // always force a redraw of window frames if they intersected a transWin before the move
  310.             DiffRgn (((WindowPeek)theWindow)->strucRgn, ((WindowPeek)theWindow)->contRgn, wm_visRgn);
  311.             PaintOne (theWindow, wm_visRgn);
  312.         }
  313.         
  314.         if (wm_transWindow)
  315.             PaintBehindTransparent();
  316.         else
  317.             AssureOldWindowLocationIsRefreshed (theWindow, wm_origStrucRgn);
  318.         
  319.         SetPort (wm_curPort);
  320.         wm_workLevel--;
  321.     }
  322.     else
  323.         CallUniversalProc (gOldMoveWindow, kMoveWindowProcInfo, theWindow, hGlobal, vGlobal, front);
  324. }
  325.  
  326.  
  327. // this may be used to guarantee that transparent windows are cleaned up if the
  328. // user calls CloseWindow() instead of CloseTransparentWindow()
  329. pascal void X_Ray_CloseWindow (WindowPtr theWindow)
  330. {
  331.     if (wm_workLevel == 0)
  332.     {
  333.         wm_workLevel++;
  334.         
  335.         CallUniversalProc (gOldCloseWindow, kCloseWindowProcInfo, theWindow);
  336.         
  337.         wm_workLevel--;
  338.     }
  339.     else
  340.         CallUniversalProc (gOldCloseWindow, kCloseWindowProcInfo, theWindow);
  341. }
  342.  
  343.  
  344. pascal void X_Ray_SizeWindow (WindowPtr theWindow, short w, short h, Boolean fUpdate)
  345. {
  346.     THz                curZone;
  347.     GWorldFlags        ugwResult;
  348.     RgnHandle        curVisRgn = nil;
  349.     RGBColor        transColor;
  350.     OSErr            err;
  351.     
  352.     if (wm_workLevel == 0)
  353.     {
  354.         wm_workLevel++;
  355.         GetPort (&wm_curPort);
  356.         GetGWorld (&wm_origGWorld, &wm_origGDH);
  357.         
  358.         SetPort (theWindow); // to get proper graphics coordinates
  359.         CopyRgn (theWindow->visRgn, wm_visRgn);
  360.         X_Ray_LocalToGlobalRgn (wm_visRgn);
  361.         
  362.         wm_transWindow = X_Ray_GetWindowRec (theWindow);
  363.         wm_intersection = PortDoesIntersect (theWindow, wm_visRgn);
  364.         
  365.         if (wm_transWindow)
  366.         {
  367.             // preserve old visRgn before window is resized
  368.             SetPort ((*wm_transWindow)->theWindow);
  369.             CopyRgn (((*wm_transWindow)->theWindow)->visRgn, wm_transVisRgn);
  370.             X_Ray_LocalToGlobalRgn (wm_transVisRgn);
  371.             SetPort (wm_curPort);
  372.             CopyRgn (((WindowPeek)((*wm_transWindow)->theWindow))->strucRgn, wm_transStrucRgn);
  373.         }
  374.         else
  375.             CopyRgn (((WindowPeek)theWindow)->strucRgn, wm_origStrucRgn);
  376.         
  377.         if (wm_intersection)
  378.         {
  379.             //DebugStr ("\presize intersects trans wins");
  380.             // the resizing window intersects at least one transWin
  381.             
  382.             curVisRgn = NewRgn();
  383.             
  384.             wm_curIntersection = wm_intersection;
  385.             while (wm_curIntersection) // walk forward through all trans wins to determine who all intersects
  386.             {
  387.                 SetPort ((*wm_curIntersection)->theWindow); // to get proper screen coordinates
  388.                 CopyRgn ((*wm_curIntersection)->theWindow->visRgn, curVisRgn);
  389.                 X_Ray_LocalToGlobalRgn (curVisRgn);
  390.                 SectRgn (wm_visRgn, curVisRgn, curVisRgn);
  391.                 
  392.                 SetPort (theWindow);
  393.                 X_Ray_GlobalToLocalRgn (curVisRgn);
  394.                 InvalRgn (curVisRgn);
  395.                 
  396.                 wm_tempWin = wm_curIntersection;
  397.                 wm_curIntersection = GetNextWindowAbove (wm_curIntersection);
  398.             }
  399.             
  400.             DisposeRgn (curVisRgn);
  401.             SetPort (wm_curPort);
  402.         }
  403.         
  404.         CallUniversalProc (gOldSizeWindow, kSizeWindowProcInfo, theWindow, w, h, fUpdate);
  405.         
  406.         if (wm_transWindow)
  407.         {
  408.             HLock ((Handle)wm_transWindow);
  409.             
  410.             curZone = GetZone(); // make sure any memory is allocated in system heap
  411.             SetZone (SystemZone());
  412.             
  413.             ugwResult = UpdateGWorld (&(*wm_transWindow)->underBuffer, 32, &(*wm_transWindow)->theWindow->portRect, nil, nil, 0);
  414.             err = QDError();
  415.             if (err != noErr)
  416.             {
  417.                 DebugNum (err);
  418.                 DebugStr ("\punderBuffer");
  419.             }
  420.             else
  421.             {
  422.                 SetGWorld ((*wm_transWindow)->underBuffer, nil);
  423.                 ForeColor (blackColor);
  424.                 BackColor (whiteColor);
  425.                 LockPixels (GetGWorldPixMap((*wm_transWindow)->underBuffer));
  426.                 EraseRect (&(*wm_transWindow)->underBuffer->portRect);
  427.                 UnlockPixels (GetGWorldPixMap((*wm_transWindow)->underBuffer));
  428.             }
  429.             
  430.             ugwResult = UpdateGWorld (&(*wm_transWindow)->contentBuffer, 32, &(*wm_transWindow)->theWindow->portRect, nil, nil, 0);
  431.             err = QDError();
  432.             err = QDError();
  433.             if (err != noErr)
  434.             {
  435.                 DebugNum (err);
  436.                 DebugStr ("\pcontentBuffer");
  437.             }
  438.             else
  439.             {
  440.                 SetGWorld ((*wm_transWindow)->contentBuffer, nil);
  441.                 ForeColor (blackColor);
  442.                 BackColor (whiteColor);
  443.                 LockPixels (GetGWorldPixMap((*wm_transWindow)->contentBuffer));
  444.                 EraseRect (&(*wm_transWindow)->contentBuffer->portRect);
  445.                 UnlockPixels (GetGWorldPixMap((*wm_transWindow)->contentBuffer));
  446.             }
  447.             
  448.             ugwResult = UpdateGWorld (&(*wm_transWindow)->mixBuffer, 32, &(*wm_transWindow)->theWindow->portRect, nil, nil, 0);
  449.             err = QDError();
  450.             if (err != noErr)
  451.             {
  452.                 DebugNum (err);
  453.                 DebugStr ("\pmixBuffer");
  454.             }
  455.             else
  456.             {
  457.                 SetGWorld ((*wm_transWindow)->mixBuffer, nil);
  458.                 ForeColor (blackColor);
  459.                 BackColor (whiteColor);
  460.                 LockPixels (GetGWorldPixMap((*wm_transWindow)->mixBuffer));
  461.                 EraseRect (&(*wm_transWindow)->mixBuffer->portRect);
  462.                 UnlockPixels (GetGWorldPixMap((*wm_transWindow)->mixBuffer));
  463.             }
  464.             
  465.             ugwResult = UpdateGWorld (&(*wm_transWindow)->maskBuffer, 32, &(*wm_transWindow)->theWindow->portRect, nil, nil, 0);
  466.             err = QDError();
  467.             if (err != noErr)
  468.             {
  469.                 DebugNum (err);
  470.                 DebugStr ("\pmaskBuffer");
  471.             }
  472.             else
  473.             {
  474.                 SetGWorld ((*wm_transWindow)->maskBuffer, nil);
  475.                 transColor.red = transColor.green = transColor.blue = (*wm_transWindow)->transparency;
  476.                 RGBForeColor (&transColor);
  477.                 LockPixels (GetGWorldPixMap((*wm_transWindow)->maskBuffer));
  478.                 PaintRect (&(*wm_transWindow)->maskBuffer->portRect);
  479.                 UnlockPixels (GetGWorldPixMap((*wm_transWindow)->maskBuffer));
  480.                 BackColor (whiteColor);
  481.                 ForeColor (blackColor);
  482.             }
  483.                                     
  484.             HUnlock ((Handle)wm_transWindow);
  485.             
  486.             SetGWorld (wm_origGWorld, wm_origGDH); // restore gworld environment
  487.             
  488.             SetPort ((*wm_transWindow)->theWindow);
  489.             InvalRect (&(*wm_transWindow)->theWindow->portRect);
  490.             
  491.             SetPort (wm_curPort);
  492.             
  493.             SetZone (curZone);
  494.             
  495.             PaintBehindTransparent();
  496.         }
  497.         else
  498.             AssureOldWindowLocationIsRefreshed (theWindow, wm_origStrucRgn);
  499.         
  500.         if (wm_intersection)
  501.         {
  502.             // always force a redraw of window frames if they intersected a transWin before the resize
  503.             DiffRgn (((WindowPeek)theWindow)->strucRgn, ((WindowPeek)theWindow)->contRgn, wm_visRgn);
  504.             PaintOne (theWindow, wm_visRgn);
  505.         }
  506.         
  507.         SetGWorld (wm_origGWorld, wm_origGDH); // restore gworld environment
  508.         SetPort (wm_curPort);
  509.         wm_workLevel--;
  510.     }
  511.     else
  512.         CallUniversalProc (gOldSizeWindow, kSizeWindowProcInfo, theWindow, w, h, fUpdate);
  513. }
  514.  
  515.  
  516. pascal long X_Ray_GrowWindow (WindowPtr theWindow, Point startPt, const Rect *bBox)
  517. {
  518.     THz                curZone;
  519.     GWorldFlags        ugwResult;
  520.     RgnHandle        curVisRgn = nil;
  521.     long            result = 0;
  522.     OSErr            err;
  523.     RGBColor        transColor;
  524.     
  525.     if (wm_workLevel == 0)
  526.     {
  527.         wm_workLevel++;
  528.         GetPort (&wm_curPort);
  529.         
  530.         SetPort (theWindow); // to get proper graphics coordinates
  531.         CopyRgn (theWindow->visRgn, wm_visRgn);
  532.         X_Ray_LocalToGlobalRgn (wm_visRgn);
  533.         
  534.         wm_transWindow = X_Ray_GetWindowRec (theWindow);
  535.         wm_intersection = PortDoesIntersect (theWindow, wm_visRgn);
  536.         
  537.         if (wm_transWindow)
  538.         {
  539.             // preserve old visRgn before window is grown
  540.             SetPort ((*wm_transWindow)->theWindow);
  541.             CopyRgn (((*wm_transWindow)->theWindow)->visRgn, wm_transVisRgn);
  542.             X_Ray_LocalToGlobalRgn (wm_transVisRgn);
  543.             SetPort (wm_curPort);
  544.             CopyRgn (((WindowPeek)((*wm_transWindow)->theWindow))->strucRgn, wm_transStrucRgn);
  545.         }
  546.         
  547.         if (wm_intersection)
  548.         {            
  549.             // the growing window intersects at least one transWin
  550.             
  551.             curVisRgn = NewRgn();
  552.             
  553.             wm_curIntersection = wm_intersection;
  554.             while (wm_curIntersection) // walk forward through all trans wins to determine who all intersects
  555.             {
  556.                 SetPort ((*wm_curIntersection)->theWindow); // to get proper screen coordinates
  557.                 CopyRgn ((*wm_curIntersection)->theWindow->visRgn, curVisRgn);
  558.                 X_Ray_LocalToGlobalRgn (curVisRgn);
  559.                 SectRgn (wm_visRgn, curVisRgn, curVisRgn);
  560.                 
  561.                 SetPort (theWindow);
  562.                 X_Ray_GlobalToLocalRgn (curVisRgn);
  563.                 InvalRgn (curVisRgn);
  564.                 
  565.                 wm_tempWin = wm_curIntersection;
  566.                 wm_curIntersection = GetNextWindowAbove (wm_curIntersection);
  567.             }
  568.             
  569.             DisposeRgn (curVisRgn);
  570.             SetPort (wm_curPort);
  571.         }
  572.         
  573.         result = CallUniversalProc (gOldGrowWindow, kGrowWindowProcInfo, theWindow, startPt, bBox);
  574.         
  575.         if (wm_intersection)
  576.         {
  577.             // always force a redraw of window frames if they intersected a transWin before the growing
  578.             DiffRgn (((WindowPeek)theWindow)->strucRgn, ((WindowPeek)theWindow)->contRgn, wm_visRgn);
  579.             PaintOne (theWindow, wm_visRgn);
  580.         }
  581.         
  582.         if (wm_transWindow && result)
  583.         {
  584.             HLock ((Handle)wm_transWindow);
  585.             
  586.             curZone = GetZone(); // make sure any memory is allocated in system heap
  587.             SetZone (SystemZone());
  588.             
  589.             ugwResult = UpdateGWorld (&(*wm_transWindow)->underBuffer, 32, &(*wm_transWindow)->theWindow->portRect, nil, nil, 0);
  590.             err = QDError();
  591.             if (err != noErr)
  592.             {
  593.                 DebugNum (err);
  594.                 DebugStr ("\punderBuffer");
  595.             }
  596.             else
  597.             {
  598.                 SetGWorld ((*wm_transWindow)->underBuffer, nil);
  599.                 ForeColor (blackColor);
  600.                 BackColor (whiteColor);
  601.                 LockPixels (GetGWorldPixMap((*wm_transWindow)->underBuffer));
  602.                 EraseRect (&(*wm_transWindow)->underBuffer->portRect);
  603.                 UnlockPixels (GetGWorldPixMap((*wm_transWindow)->underBuffer));
  604.             }
  605.             
  606.             ugwResult = UpdateGWorld (&(*wm_transWindow)->contentBuffer, 32, &(*wm_transWindow)->theWindow->portRect, nil, nil, 0);
  607.             err = QDError();
  608.             err = QDError();
  609.             if (err != noErr)
  610.             {
  611.                 DebugNum (err);
  612.                 DebugStr ("\pcontentBuffer");
  613.             }
  614.             else
  615.             {
  616.                 SetGWorld ((*wm_transWindow)->contentBuffer, nil);
  617.                 ForeColor (blackColor);
  618.                 BackColor (whiteColor);
  619.                 LockPixels (GetGWorldPixMap((*wm_transWindow)->contentBuffer));
  620.                 EraseRect (&(*wm_transWindow)->contentBuffer->portRect);
  621.                 UnlockPixels (GetGWorldPixMap((*wm_transWindow)->contentBuffer));
  622.             }
  623.             
  624.             ugwResult = UpdateGWorld (&(*wm_transWindow)->mixBuffer, 32, &(*wm_transWindow)->theWindow->portRect, nil, nil, 0);
  625.             err = QDError();
  626.             if (err != noErr)
  627.             {
  628.                 DebugNum (err);
  629.                 DebugStr ("\pmixBuffer");
  630.             }
  631.             else
  632.             {
  633.                 SetGWorld ((*wm_transWindow)->mixBuffer, nil);
  634.                 ForeColor (blackColor);
  635.                 BackColor (whiteColor);
  636.                 LockPixels (GetGWorldPixMap((*wm_transWindow)->mixBuffer));
  637.                 EraseRect (&(*wm_transWindow)->mixBuffer->portRect);
  638.                 UnlockPixels (GetGWorldPixMap((*wm_transWindow)->mixBuffer));
  639.             }
  640.             
  641.             ugwResult = UpdateGWorld (&(*wm_transWindow)->maskBuffer, 32, &(*wm_transWindow)->theWindow->portRect, nil, nil, 0);
  642.             err = QDError();
  643.             if (err != noErr)
  644.             {
  645.                 DebugNum (err);
  646.                 DebugStr ("\pmaskBuffer");
  647.             }
  648.             else
  649.             {
  650.                 SetGWorld ((*wm_transWindow)->maskBuffer, nil);
  651.                 transColor.red = transColor.green = transColor.blue = (*wm_transWindow)->transparency;
  652.                 RGBForeColor (&transColor);
  653.                 LockPixels (GetGWorldPixMap((*wm_transWindow)->maskBuffer));
  654.                 PaintRect (&(*wm_transWindow)->maskBuffer->portRect);
  655.                 UnlockPixels (GetGWorldPixMap((*wm_transWindow)->maskBuffer));
  656.                 BackColor (whiteColor);
  657.                 ForeColor (blackColor);
  658.             }
  659.                                     
  660.             HUnlock ((Handle)wm_transWindow);
  661.             
  662.             SetGWorld (wm_origGWorld, wm_origGDH); // restore gworld environment
  663.             
  664.             SetPort ((*wm_transWindow)->theWindow);
  665.             InvalRect (&(*wm_transWindow)->theWindow->portRect);
  666.             
  667.             SetPort (wm_curPort); // restore graphics environment
  668.             
  669.             SetZone (curZone);
  670.             
  671.             PaintBehindTransparent();
  672.         }
  673.         
  674.         SetPort (wm_curPort);
  675.         wm_workLevel--;
  676.     }
  677.     else
  678.         result = CallUniversalProc (gOldGrowWindow, kGrowWindowProcInfo, theWindow, startPt, bBox);
  679.     
  680.     return result;
  681. }
  682.  
  683.  
  684. pascal void X_Ray_HideWindow (WindowPtr theWindow)
  685. {
  686.     if (wm_workLevel == 0)
  687.     {
  688.         wm_workLevel++;
  689.         GetPort (&wm_curPort);
  690.         
  691.         wm_transWindow = X_Ray_GetWindowRec (theWindow);
  692.         if (wm_transWindow)
  693.             ReorderWindow (wm_transWindow, kROMethod_HideWindow, (WindowPtr)((WindowPeek)theWindow)->nextWindow);
  694.         
  695.         CallUniversalProc (gOldHideWindow, kHideWindowProcInfo, theWindow);
  696.         
  697.         SetPort (wm_curPort);
  698.         wm_workLevel--;
  699.     }
  700.     else
  701.         CallUniversalProc (gOldHideWindow, kHideWindowProcInfo, theWindow);
  702. }
  703.  
  704.  
  705. pascal void X_Ray_ShowWindow (WindowPtr theWindow)
  706. {
  707.     if (wm_workLevel == 0)
  708.     {
  709.         wm_workLevel++;
  710.         GetPort (&wm_curPort);
  711.         
  712.         wm_transWindow = X_Ray_GetWindowRec (theWindow);
  713.         
  714.         CallUniversalProc (gOldShowWindow, kShowWindowProcInfo, theWindow);
  715.         
  716.         if (wm_transWindow)
  717.             PaintBehindTransparent();
  718.         
  719.         SetPort (wm_curPort);
  720.         wm_workLevel--;
  721.     }
  722.     else
  723.         CallUniversalProc (gOldShowWindow, kShowWindowProcInfo, theWindow);        
  724. }
  725.  
  726.  
  727. pascal void X_Ray_ShowHide (WindowPtr theWindow, Boolean showFlag)
  728. {
  729.     if (wm_workLevel == 0)
  730.     {
  731.         wm_workLevel++;
  732.         GetPort (&wm_curPort);
  733.         
  734.         wm_transWindow = X_Ray_GetWindowRec (theWindow);
  735.         
  736.         // this conditional statement must occur BEFORE CallUniversalProc
  737.         if (!showFlag) // window is being hidden, if it is frontMost, hidding it will reorder it
  738.             if (wm_transWindow && (LMGetWindowList() == theWindow))
  739.                 ReorderWindow (wm_transWindow, kROMethod_ShowHide, (WindowPtr)((WindowPeek)theWindow)->nextWindow);
  740.         
  741.         CallUniversalProc (gOldShowHide, kShowHideProcInfo, theWindow, showFlag);
  742.         
  743.         if (showFlag && wm_transWindow)
  744.             PaintBehindTransparent();
  745.         
  746.         SetPort (wm_curPort);
  747.         wm_workLevel--;
  748.     }
  749.     else
  750.         CallUniversalProc (gOldShowHide, kShowHideProcInfo, theWindow, showFlag);
  751. }
  752.  
  753.  
  754. pascal void X_Ray_BringToFront (WindowPtr theWindow)
  755. {
  756.     X_Ray_AppRecHandle        switchedApp;
  757.     RgnHandle                intersectRgn = nil, updateRgn = nil;
  758.     WindowPtr                curWindow = nil, repaintWindow = nil;
  759.     
  760.     if (wm_workLevel == 0)
  761.     {
  762.         wm_workLevel++;        
  763.         GetPort (&wm_curPort);
  764.         
  765.         switchedApp = WindowIsGlobalAppWindow (theWindow);
  766.         if (switchedApp)
  767.         {
  768.             updateRgn = ReorderApp (switchedApp, kROMethod_BringToFront);
  769.             CleanAppList();
  770.         }
  771.         else
  772.         {
  773.             wm_transWindow = X_Ray_GetWindowRec (theWindow);
  774.             if (wm_transWindow)
  775.             {
  776.                 CopyRgn (theWindow->visRgn, wm_transReorderVisRgn); // needed for AssureUpdateForTransparent()
  777.                 ReorderWindow (wm_transWindow, kROMethod_BringToFront, nil);
  778.             }
  779.         }
  780.         
  781.         CallUniversalProc (gOldBringToFront, kBringToFrontProcInfo, theWindow);
  782.         
  783.         // force a redraw of new forground app's windows that may intersect
  784.         // transparent windows of the app that was foreground
  785.         if (switchedApp && updateRgn && !EmptyRgn (updateRgn))
  786.         {
  787.             intersectRgn = NewRgn();
  788.             
  789.             curWindow = GetFirstLayerWindow ((LayerPtr)(*switchedApp)->appGlobalWindow);
  790.             while (curWindow)
  791.             {
  792.                 SectRgn (updateRgn, ((WindowPeek)curWindow)->strucRgn, intersectRgn);
  793.                 if (!EmptyRgn (intersectRgn))
  794.                     repaintWindow = curWindow; // remember the back most window for PaintOne()
  795.                 curWindow = (WindowPtr)((WindowPeek)curWindow)->nextWindow;
  796.             }
  797.             
  798.             if (repaintWindow)
  799.                 PaintOne (repaintWindow, updateRgn);
  800.             
  801.             DisposeRgn (intersectRgn);
  802.             DisposeRgn (updateRgn);
  803.         }
  804.         
  805.         if (switchedApp)
  806.         {
  807.             wm_transWindow = (*switchedApp)->windowList;
  808.             while (wm_transWindow)
  809.             {
  810.                 PaintBehindTransparent();
  811.                 wm_transWindow = (*wm_transWindow)->nextWindow;
  812.             }
  813.         }
  814.         else
  815.         {
  816.             if (wm_transWindow)
  817.                 AssureUpdateForTransparent (theWindow);
  818.             else
  819.                 AssureMovingWindowIsRefreshed (theWindow);
  820.         }
  821.         
  822.         SetPort (wm_curPort);
  823.         wm_workLevel--;
  824.     }
  825.     else
  826.         CallUniversalProc (gOldBringToFront, kBringToFrontProcInfo, theWindow);
  827. }
  828.  
  829.  
  830. pascal void X_Ray_SelectWindow (WindowPtr theWindow)
  831. {
  832.     if (wm_workLevel == 0)
  833.     {
  834.         wm_workLevel++;
  835.         GetPort (&wm_curPort);
  836.         
  837.         wm_transWindow = X_Ray_GetWindowRec (theWindow);
  838.         if (wm_transWindow)
  839.         {
  840.             //DebugStr ("\pX_Ray_SelectWindow");
  841.             CopyRgn (theWindow->visRgn, wm_transReorderVisRgn); // needed for assuring a proper update after reorder
  842.             ReorderWindow (wm_transWindow, kROMethod_SelectWindow, nil);
  843.         }
  844.         
  845.         CallUniversalProc (gOldSelectWindow, kSelectWindowProcInfo, theWindow);
  846.         
  847.         AssureMovingWindowIsRefreshed (theWindow);
  848.         
  849.         if (wm_transWindow)
  850.         {
  851.             AssureUpdateForTransparent (theWindow);
  852.             PaintBehindTransparent();
  853.         }
  854.         
  855.         SetPort (wm_curPort);
  856.         wm_workLevel--;
  857.     }
  858.     else
  859.         CallUniversalProc (gOldSelectWindow, kSelectWindowProcInfo, theWindow);
  860. }
  861.  
  862.  
  863. pascal void X_Ray_DragWindow (WindowPtr theWindow, Point startPt, const Rect *boundsRect)
  864. {
  865.     RgnHandle    curVisRgn;
  866.     
  867.     if (wm_workLevel == 0)
  868.     {
  869.         wm_workLevel++;
  870.         GetPort (&wm_curPort);
  871.         
  872.         SetPort (theWindow); // to get proper graphics coordinates
  873.         CopyRgn (theWindow->visRgn, wm_visRgn);
  874.         X_Ray_LocalToGlobalRgn (wm_visRgn);
  875.         
  876.         wm_transWindow = X_Ray_GetWindowRec (theWindow);
  877.         wm_intersection = PortDoesIntersect (theWindow, wm_visRgn);
  878.         
  879.         if (wm_transWindow)
  880.         {
  881.             if (!isPressed(0x37)) // if command key is not down
  882.             {
  883.                 //DebugStr ("\pX_Ray_DragWindow");
  884.                 ReorderWindow (wm_transWindow, kROMethod_DragWindow, nil);
  885.             }
  886.             
  887.             // preserve old visRgn before window is moved
  888.             SetPort ((*wm_transWindow)->theWindow);
  889.             CopyRgn (((*wm_transWindow)->theWindow)->visRgn, wm_transVisRgn);
  890.             X_Ray_LocalToGlobalRgn (wm_transVisRgn);
  891.             SetPort (wm_curPort);
  892.             CopyRgn (((WindowPeek)((*wm_transWindow)->theWindow))->strucRgn, wm_transStrucRgn);
  893.         }
  894.         else
  895.             CopyRgn (((WindowPeek)theWindow)->strucRgn, wm_origStrucRgn);
  896.         
  897.         if (wm_intersection)
  898.         {            
  899.             // the moving window's visRgn does intersect at least one transWin
  900.             
  901.             curVisRgn = NewRgn();
  902.             
  903.             wm_curIntersection = wm_intersection;
  904.             while (wm_curIntersection) // walk forward through all trans wins to determine who all intersects
  905.             {
  906.                 SetPort ((*wm_curIntersection)->theWindow); // to get proper screen coordinates
  907.                 CopyRgn ((*wm_curIntersection)->theWindow->visRgn, curVisRgn);
  908.                 X_Ray_LocalToGlobalRgn (curVisRgn);
  909.                 SectRgn (wm_visRgn, curVisRgn, curVisRgn);
  910.                 SetPort (theWindow);
  911.                 X_Ray_GlobalToLocalRgn (curVisRgn);
  912.                 InvalRgn (curVisRgn);
  913.                 
  914.                 wm_tempWin = wm_curIntersection;
  915.                 
  916.                 wm_curIntersection = GetNextWindowAbove (wm_curIntersection);
  917.             }
  918.             
  919.             DisposeRgn (curVisRgn);
  920.             SetPort (wm_curPort);
  921.         }
  922.         
  923.         CallUniversalProc (gOldDragWindow, kDragWindowProcInfo, theWindow, startPt, boundsRect);
  924.         
  925.         // check to see if window intersects any transparent windows behind it after the move
  926.         // this fixes a problem with window frames and contents not redrawing correctly after a move
  927.         if (!isPressed(0x37)) // if command key is not down
  928.             AssureMovingWindowIsRefreshed (theWindow);
  929.         
  930.         if (wm_intersection)
  931.         {
  932.             // always force a redraw of window frames if they intersected a transWin before the move
  933.             DiffRgn (((WindowPeek)theWindow)->strucRgn, ((WindowPeek)theWindow)->contRgn, wm_visRgn);
  934.             PaintOne (theWindow, wm_visRgn);
  935.         }
  936.         
  937.         if (wm_transWindow)
  938.             PaintBehindTransparent();
  939.         else
  940.             AssureOldWindowLocationIsRefreshed (theWindow, wm_origStrucRgn);
  941.         
  942.         SetPort (wm_curPort);
  943.         wm_workLevel--;
  944.     }
  945.     else
  946.         CallUniversalProc (gOldDragWindow, kDragWindowProcInfo, theWindow, startPt, boundsRect);
  947. }
  948.  
  949.  
  950. pascal void X_Ray_ZoomWindow (WindowPtr theWindow, short partCode, Boolean front)
  951. {
  952.     RgnHandle    curVisRgn;
  953.     THz            curZone;
  954.     GWorldFlags    ugwResult;
  955.     OSErr        err;
  956.     RGBColor    transColor;
  957.     
  958.     if (wm_workLevel == 0)
  959.     {
  960.         wm_workLevel++;
  961.         GetPort (&wm_curPort);
  962.         GetGWorld (&wm_origGWorld, &wm_origGDH);
  963.         
  964.         SetPort (theWindow); // to get proper graphics coordinates
  965.         CopyRgn (theWindow->visRgn, wm_visRgn);
  966.         X_Ray_LocalToGlobalRgn (wm_visRgn);
  967.         
  968.         wm_transWindow = X_Ray_GetWindowRec (theWindow);
  969.         wm_intersection = PortDoesIntersect (theWindow, wm_visRgn);
  970.         
  971.         if (wm_transWindow)
  972.         {
  973.             // preserve old visRgn before window is resized
  974.             SetPort ((*wm_transWindow)->theWindow);
  975.             CopyRgn (((*wm_transWindow)->theWindow)->visRgn, wm_transVisRgn);
  976.             X_Ray_LocalToGlobalRgn (wm_transVisRgn);
  977.             SetPort (wm_curPort);
  978.             CopyRgn (((WindowPeek)((*wm_transWindow)->theWindow))->strucRgn, wm_transStrucRgn);
  979.         }
  980.         
  981.         if (wm_intersection)
  982.         {
  983.             //DebugStr ("\presize intersects trans wins");
  984.             // the resizing window intersects at least one transWin
  985.             
  986.             curVisRgn = NewRgn();
  987.             
  988.             wm_curIntersection = wm_intersection;
  989.             while (wm_curIntersection) // walk forward through all trans wins to determine who all intersects
  990.             {
  991.                 SetPort ((*wm_curIntersection)->theWindow); // to get proper screen coordinates
  992.                 CopyRgn ((*wm_curIntersection)->theWindow->visRgn, curVisRgn);
  993.                 X_Ray_LocalToGlobalRgn (curVisRgn);
  994.                 SectRgn (wm_visRgn, curVisRgn, curVisRgn);
  995.                 
  996.                 SetPort (theWindow);
  997.                 X_Ray_GlobalToLocalRgn (curVisRgn);
  998.                 InvalRgn (curVisRgn);
  999.                 
  1000.                 wm_tempWin = wm_curIntersection;
  1001.                 wm_curIntersection = GetNextWindowAbove (wm_curIntersection);
  1002.             }
  1003.             
  1004.             DisposeRgn (curVisRgn);
  1005.             SetPort (wm_curPort);
  1006.         }
  1007.         
  1008.         CallUniversalProc (gOldZoomWindow, kZoomWindowProcInfo, theWindow, partCode, front);
  1009.         
  1010.         if (wm_transWindow)
  1011.         {
  1012.             HLock ((Handle)wm_transWindow);
  1013.             
  1014.             curZone = GetZone(); // make sure any memory is allocated in system heap
  1015.             SetZone (SystemZone());
  1016.             
  1017.             ugwResult = UpdateGWorld (&(*wm_transWindow)->underBuffer, 32, &(*wm_transWindow)->theWindow->portRect, nil, nil, 0);
  1018.             err = QDError();
  1019.             if (err != noErr)
  1020.             {
  1021.                 DebugNum (err);
  1022.                 DebugStr ("\punderBuffer");
  1023.             }
  1024.             else
  1025.             {
  1026.                 SetGWorld ((*wm_transWindow)->underBuffer, nil);
  1027.                 ForeColor (blackColor);
  1028.                 BackColor (whiteColor);
  1029.                 LockPixels (GetGWorldPixMap((*wm_transWindow)->underBuffer));
  1030.                 EraseRect (&(*wm_transWindow)->underBuffer->portRect);
  1031.                 UnlockPixels (GetGWorldPixMap((*wm_transWindow)->underBuffer));
  1032.             }
  1033.             
  1034.             ugwResult = UpdateGWorld (&(*wm_transWindow)->contentBuffer, 32, &(*wm_transWindow)->theWindow->portRect, nil, nil, 0);
  1035.             err = QDError();
  1036.             err = QDError();
  1037.             if (err != noErr)
  1038.             {
  1039.                 DebugNum (err);
  1040.                 DebugStr ("\pcontentBuffer");
  1041.             }
  1042.             else
  1043.             {
  1044.                 SetGWorld ((*wm_transWindow)->contentBuffer, nil);
  1045.                 ForeColor (blackColor);
  1046.                 BackColor (whiteColor);
  1047.                 LockPixels (GetGWorldPixMap((*wm_transWindow)->contentBuffer));
  1048.                 EraseRect (&(*wm_transWindow)->contentBuffer->portRect);
  1049.                 UnlockPixels (GetGWorldPixMap((*wm_transWindow)->contentBuffer));
  1050.             }
  1051.             
  1052.             ugwResult = UpdateGWorld (&(*wm_transWindow)->mixBuffer, 32, &(*wm_transWindow)->theWindow->portRect, nil, nil, 0);
  1053.             err = QDError();
  1054.             if (err != noErr)
  1055.             {
  1056.                 DebugNum (err);
  1057.                 DebugStr ("\pmixBuffer");
  1058.             }
  1059.             else
  1060.             {
  1061.                 SetGWorld ((*wm_transWindow)->mixBuffer, nil);
  1062.                 ForeColor (blackColor);
  1063.                 BackColor (whiteColor);
  1064.                 LockPixels (GetGWorldPixMap((*wm_transWindow)->mixBuffer));
  1065.                 EraseRect (&(*wm_transWindow)->mixBuffer->portRect);
  1066.                 UnlockPixels (GetGWorldPixMap((*wm_transWindow)->mixBuffer));
  1067.             }
  1068.             
  1069.             ugwResult = UpdateGWorld (&(*wm_transWindow)->maskBuffer, 32, &(*wm_transWindow)->theWindow->portRect, nil, nil, 0);
  1070.             err = QDError();
  1071.             if (err != noErr)
  1072.             {
  1073.                 DebugNum (err);
  1074.                 DebugStr ("\pmaskBuffer");
  1075.             }
  1076.             else
  1077.             {
  1078.                 SetGWorld ((*wm_transWindow)->maskBuffer, nil);
  1079.                 transColor.red = transColor.green = transColor.blue = (*wm_transWindow)->transparency;
  1080.                 RGBForeColor (&transColor);
  1081.                 LockPixels (GetGWorldPixMap((*wm_transWindow)->maskBuffer));
  1082.                 PaintRect (&(*wm_transWindow)->maskBuffer->portRect);
  1083.                 UnlockPixels (GetGWorldPixMap((*wm_transWindow)->maskBuffer));
  1084.                 BackColor (whiteColor);
  1085.                 ForeColor (blackColor);
  1086.             }
  1087.                                     
  1088.             HUnlock ((Handle)wm_transWindow);
  1089.             
  1090.             SetGWorld (wm_origGWorld, wm_origGDH); // restore gworld environment
  1091.             
  1092.             SetPort ((*wm_transWindow)->theWindow);
  1093.             InvalRect (&(*wm_transWindow)->theWindow->portRect);
  1094.             
  1095.             SetPort (wm_curPort); // restore graphics environment
  1096.             
  1097.             SetZone (curZone);
  1098.             
  1099.             PaintBehindTransparent();
  1100.         }
  1101.         
  1102.         if (wm_intersection)
  1103.         {
  1104.             // always force a redraw of window frames if they intersected a transWin before the resize
  1105.             DiffRgn (((WindowPeek)theWindow)->strucRgn, ((WindowPeek)theWindow)->contRgn, wm_visRgn);
  1106.             PaintOne (theWindow, wm_visRgn);
  1107.         }
  1108.         
  1109.         SetGWorld (wm_origGWorld, wm_origGDH);
  1110.         SetPort (wm_curPort);
  1111.         wm_workLevel--;
  1112.     }
  1113.     else
  1114.         CallUniversalProc (gOldZoomWindow, kZoomWindowProcInfo, theWindow, partCode, front);
  1115. }
  1116.  
  1117. pascal void X_Ray_SendBehind (WindowPtr theWindow, WindowPtr behindWindow)
  1118. {
  1119.     if (wm_workLevel == 0)
  1120.     {
  1121.         wm_workLevel++;
  1122.         GetPort (&wm_curPort);
  1123.         
  1124.         wm_transWindow = X_Ray_GetWindowRec (theWindow);
  1125.         if (wm_transWindow)
  1126.         {
  1127.             //DebugStr ("\pX_Ray_SendBehind");
  1128.             ReorderWindow (wm_transWindow, kROMethod_SendBehind, behindWindow);
  1129.         }
  1130.         
  1131.         CallUniversalProc (gOldSendBehind, kSendBehindProcInfo, theWindow, behindWindow);
  1132.         
  1133.         SetPort (wm_curPort);
  1134.         wm_workLevel--;
  1135.     }
  1136.     else
  1137.         CallUniversalProc (gOldSendBehind, kSendBehindProcInfo, theWindow, behindWindow);
  1138. }
  1139.  
  1140.  
  1141. pascal short X_Ray_FindWindow (Point thePoint, WindowPtr *theWindow)
  1142. {
  1143.     short                    winPart;
  1144.     long                    result;
  1145.     X_Ray_WindowHandle        curTransWindow;
  1146.     WindowPtr                curWindow;
  1147.     GrafPtr                    curPort;
  1148.     
  1149.     // this definately works when the foreground app has transWins but doesn't bring background apps forward if they have transWins
  1150.     
  1151.     // this is a hack to build proper bounds for FindWindow to find transparent windows
  1152.     // basically all regions FindWindow checks are modified to mimic what FindWindow expects to find
  1153.     GetPort (&curPort);
  1154.     
  1155.     curTransWindow = GetNextWindowBehind (nil);
  1156.     while (curTransWindow)
  1157.     {
  1158.         if ((*curTransWindow)->transparency == kTransparencyOpaque)
  1159.         {
  1160.             SetPort ((*curTransWindow)->theWindow);
  1161.             CopyRgn (((*curTransWindow)->theWindow)->visRgn, wm_findWindowVisRgn);
  1162.             X_Ray_LocalToGlobalRgn (wm_findWindowVisRgn);
  1163.             if (!((*curTransWindow)->windowKind&kTSMWindow))
  1164.                 UnionRgn (((WindowPeek)(*(*curTransWindow)->owner)->appGlobalWindow)->strucRgn, wm_findWindowVisRgn, ((WindowPeek)(*(*curTransWindow)->owner)->appGlobalWindow)->strucRgn);
  1165.             UnionRgn (((WindowPeek)(*curTransWindow)->theWindow)->strucRgn, ((WindowPeek)(*curTransWindow)->theWindow)->contRgn, ((WindowPeek)(*curTransWindow)->theWindow)->strucRgn);
  1166.         }
  1167.         
  1168.         curTransWindow = GetNextWindowBehind (curTransWindow);
  1169.     }
  1170.     SetPort (curPort);
  1171.     
  1172.     result = CallUniversalProc (gOldFindWindow, kFindWindowProcInfo, thePoint, theWindow);
  1173.     winPart = LoWord (result);
  1174.     
  1175.     curTransWindow = GetNextWindowBehind (nil);
  1176.     while (curTransWindow)
  1177.     {
  1178.         if ((*curTransWindow)->transparency == kTransparencyOpaque)
  1179.         {
  1180.             SetPort ((*curTransWindow)->theWindow);
  1181.             CopyRgn (((*curTransWindow)->theWindow)->visRgn, wm_findWindowVisRgn);
  1182.             X_Ray_LocalToGlobalRgn (wm_findWindowVisRgn);
  1183.             if (!((*curTransWindow)->windowKind&kTSMWindow))
  1184.             {
  1185.                 DiffRgn (((WindowPeek)(*(*curTransWindow)->owner)->appGlobalWindow)->strucRgn, wm_findWindowVisRgn, ((WindowPeek)(*(*curTransWindow)->owner)->appGlobalWindow)->strucRgn);
  1186.                 // by subtracting from the strucRgn of the appGlobalWindow, windows beneath curTransWindow may not be included now so re-add their strucRgns
  1187.                 curWindow = (GrafPtr)((WindowPeek)(*curTransWindow)->theWindow)->nextWindow;
  1188.                 while (curWindow)
  1189.                 {
  1190.                     UnionRgn (((WindowPeek)(*(*curTransWindow)->owner)->appGlobalWindow)->strucRgn, ((WindowPeek)curWindow)->strucRgn, ((WindowPeek)(*(*curTransWindow)->owner)->appGlobalWindow)->strucRgn);
  1191.                     curWindow = (GrafPtr)((WindowPeek)curWindow)->nextWindow;
  1192.                 }
  1193.             }
  1194.             DiffRgn (((WindowPeek)(*curTransWindow)->theWindow)->strucRgn, ((WindowPeek)(*curTransWindow)->theWindow)->contRgn, ((WindowPeek)(*curTransWindow)->theWindow)->strucRgn);
  1195.         }
  1196.         curTransWindow = GetNextWindowBehind (curTransWindow);
  1197.     }
  1198.     SetPort (curPort);
  1199.     
  1200.     return winPart;
  1201. }
  1202.  
  1203.  
  1204. // this needs some real handling
  1205. pascal long X_Ray_DragGrayRgn (RgnHandle theRgn, Point startPt, const Rect *limitRect, const Rect *slopRect, short axis, DragGrayRgnProcPtr actionProc)
  1206. {
  1207.     X_RayDrawLevel++; // turn off X_Ray
  1208.     
  1209.     CallUniversalProc (gOldDragGrayRgn, kDragGrayRgnProcInfo, theRgn, startPt, limitRect, slopRect, axis, actionProc);
  1210.     
  1211.     X_RayDrawLevel--; // turn on X_Ray
  1212. }
  1213.  
  1214.  
  1215. // not actually used
  1216. pascal WindowPtr X_Ray_NewWindow (void *wStorage, const Rect *boundsRect, ConstStr255Param title, Boolean visible, short theProc, WindowPtr behind, Boolean goAwayFlag, long refCon)
  1217. {
  1218.     long    result;
  1219.     
  1220.     result = CallUniversalProc (gOldNewWindow, kNewWindowProcInfo, wStorage, boundsRect, title, visible, theProc, behind, goAwayFlag, refCon);
  1221.     
  1222.     return (WindowPtr)result;
  1223. }
  1224.  
  1225.  
  1226. // not actually used
  1227. pascal WindowPtr X_Ray_NewCWindow (void *wStorage, const Rect *boundsRect, ConstStr255Param title, Boolean visible, short theProc, WindowPtr behind, Boolean goAwayFlag, long refCon)
  1228. {
  1229.     long    result;
  1230.     
  1231.     result = CallUniversalProc (gOldNewCWindow, kNewWindowProcInfo, wStorage, boundsRect, title, visible, theProc, behind, goAwayFlag, refCon);
  1232.     
  1233.     return (WindowPtr)result;
  1234. }
  1235.  
  1236.  
  1237. // not actually used
  1238. pascal WindowPtr X_Ray_GetNewWindow (short windowID, void *wStorage, WindowPtr behind)
  1239. {
  1240.     long    result;
  1241.  
  1242.     result = CallUniversalProc (gOldGetNewWindow, kGetNewWindowProcInfo, windowID, wStorage, behind);
  1243.     
  1244.     return (WindowPtr)result;
  1245. }
  1246.  
  1247.  
  1248. // not actually used
  1249. pascal WindowPtr X_Ray_GetNewCWindow (short windowID, void *wStorage, WindowPtr behind)
  1250. {
  1251.     long    result;
  1252.     
  1253.     result = CallUniversalProc (gOldGetNewCWindow, kGetNewWindowProcInfo, windowID, wStorage, behind);
  1254.     
  1255.     return (WindowPtr)result;
  1256. }
  1257.  
  1258.  
  1259. // When an app calls InitWindows() the Layer Manager makes the app's layer.
  1260. // By watching an app's InitWindows() call I can get its layer.
  1261. pascal void X_Ray_InitWindows (void)
  1262. {
  1263.     UniversalProcPtr    localOldInitWindows;
  1264.     Boolean                newApp;
  1265.     
  1266.     // figure out which app I am in and call its original InitWindows().  Ug!
  1267.     localOldInitWindows = GetLocalTrap (_InitWindows);
  1268.     CallUniversalProc (localOldInitWindows, kInitWindowsProcInfo);
  1269.     
  1270.     newApp = AppInitWindowsState();
  1271.     if (newApp)
  1272.         SetAppGlobalWindow ((WindowPtr)GetCurLayer());
  1273. }
  1274.  
  1275.  
  1276. // WINDOW MANAGER UTILITY FUNCTIONS
  1277.  
  1278. // forces redraw of all windows behind wm_transWin
  1279. // and sets update events in all intersecting windows so they will be updated behind this window
  1280. void PaintBehindTransparent (void)
  1281. {
  1282.     Boolean        firstTime = true;
  1283.     
  1284.     WindowPtr    serviceWindow, backMostStrucIntersection;
  1285.     
  1286.     // wm_transVisRgn may not always be empty, if (*wm_transWindow)->theWindow has moved
  1287.     // it will contain the old visRgn of (*wm_transWindow)->theWindow before it was moved
  1288.     SetPort ((*wm_transWindow)->theWindow);
  1289.     CopyRgn (((*wm_transWindow)->theWindow)->visRgn, wm_visRgn);
  1290.     
  1291.     X_Ray_LocalToGlobalRgn (wm_visRgn);
  1292.     UnionRgn (wm_visRgn, wm_transVisRgn, wm_transVisRgn);
  1293.     PaintBehind ((*wm_transWindow)->theWindow, wm_transVisRgn);
  1294.     CalcVisBehind ((*wm_transWindow)->theWindow, wm_transVisRgn);
  1295.     
  1296.     // wm_transStrucRgn may not always be empty, if (*wm_transWindow)->theWindow has moved/grown
  1297.     // it will contain the old strucRgn of (*wm_transWindow)->theWindow before it was moved
  1298.     // this means we now need to accumulate the new strucRgn of the moved/resized window
  1299.     if (!EmptyRgn (wm_transStrucRgn))
  1300.         UnionRgn (((WindowPeek)((*wm_transWindow)->theWindow))->strucRgn, wm_transStrucRgn, wm_transStrucRgn);
  1301.     
  1302.     SetPort (wm_curPort); // restore drawing environ
  1303.     
  1304.     // walk all windows in all apps behind (*wm_transWindow)->theWindow
  1305.     // if they are visible, comapre their visRgns (copied and made global) to the wm_transVisRgn
  1306.     // if they intersect add to their updateRgns
  1307.     // if their strucRgns intersect, redraw their window frames
  1308.     if ((*wm_transWindow)->windowKind&kTSMWindow)
  1309.         wm_curApp = gCommRec.appList;
  1310.     else
  1311.         wm_curApp = (*(*wm_transWindow)->owner)->nextApp;
  1312.     wm_curWindow = (GrafPtr)((WindowPeek)(*wm_transWindow)->theWindow)->nextWindow; // start behind the current window
  1313.     // BUGBUG this will not properly see all windows in the TSM layer
  1314.     while (wm_curApp || firstTime)
  1315.     {
  1316.         backMostStrucIntersection = nil;
  1317.         
  1318.         if (!firstTime)
  1319.         {
  1320.             if (!(((*wm_curApp)->mode)&modeOnlyBackground))
  1321.                 wm_curWindow = GetFirstLayerWindow ((*wm_curApp)->appGlobalWindow);
  1322.             else
  1323.                 wm_curWindow = nil;
  1324.         }
  1325.         
  1326.         while (wm_curWindow)
  1327.         {
  1328.             if (((WindowPeek)wm_curWindow)->visible) // only matters if window is visible
  1329.             {
  1330.                 SetPort (wm_curWindow);
  1331.                 
  1332.                 //DebugStr ("\p2 pre CopyRgn");
  1333.                 //DebugNum ((long)wm_curWindow);
  1334.                 //DebugNum ((long)wm_curWindow->visRgn);
  1335.                 
  1336.                 CopyRgn (wm_curWindow->visRgn, wm_visRgn);
  1337.                 
  1338.                 //DebugStr ("\p2 post CopyRgn");
  1339.                 //DebugStr ("\p--------");
  1340.                 
  1341.                 X_Ray_LocalToGlobalRgn (wm_visRgn);
  1342.                 SectRgn (wm_visRgn, wm_transVisRgn, wm_visRgn);
  1343.                 X_Ray_GlobalToLocalRgn (wm_visRgn);
  1344.                 InvalRgn (wm_visRgn); // force window updates that globally intersect the transparent window's new and old visRgn
  1345.                 
  1346.                 // find out the back most struRgn intersection
  1347.                 SectRgn (((WindowPeek)wm_curWindow)->strucRgn, wm_transStrucRgn, wm_strucRgn);
  1348.                 if (!EmptyRgn(wm_strucRgn))
  1349.                     backMostStrucIntersection = wm_curWindow;
  1350.             }
  1351.             
  1352.             wm_curWindow = (GrafPtr)((WindowPeek)wm_curWindow)->nextWindow;
  1353.         }
  1354.         
  1355.         // redraw back most intersecting window frame in each layer
  1356.         // this redraw will propogate forward in the layer's window list
  1357.         if (backMostStrucIntersection)
  1358.             PaintOne (backMostStrucIntersection, wm_transStrucRgn);
  1359.         
  1360.         if (!firstTime)
  1361.         {
  1362.             if (wm_curApp)
  1363.                 wm_curApp = (*wm_curApp)->nextApp;
  1364.         }
  1365.         else
  1366.             firstTime = false;
  1367.     }
  1368.     
  1369.     SetEmptyRgn (wm_transStrucRgn);
  1370.     SetEmptyRgn (wm_strucRgn);
  1371.     SetEmptyRgn (wm_transVisRgn);
  1372.     SetEmptyRgn (wm_visRgn);
  1373.     SetPort (wm_curPort); // restore drawing environ
  1374. }
  1375.  
  1376. // redraws intersecting windows of the app being switched to the foreground where they intersect a transWin
  1377. void PaintBehindOnSwitch (LayerPtr appGlobalWindow)
  1378. {
  1379.     // upon entry, wm_visRgn contains the sum of all the visRgns of all transWins of the app being switched out
  1380.     X_RayDrawLevel++; // suspend X_Ray
  1381.     
  1382.     SetPort ((*wm_transWindow)->theWindow);
  1383.     CopyRgn (((*wm_transWindow)->theWindow)->visRgn, wm_transVisRgn);
  1384.     X_Ray_LocalToGlobalRgn (wm_visRgn);
  1385.     
  1386.     SetPort (wm_curPort); // restore drawing environ
  1387.     
  1388.     // redraw all of the new apps windows
  1389.     wm_curWindow = GetFirstLayerWindow (appGlobalWindow);
  1390.     //wm_curWindow = (WindowPtr)((WindowPeek)(appGlobalWindow))->windowPic;
  1391.     while (wm_curWindow)
  1392.     {
  1393.         if (((WindowPeek)wm_curWindow)->visible) // only matters if window is visible
  1394.         {
  1395.             PaintOne (wm_curWindow, ((WindowPeek)appGlobalWindow)->strucRgn);
  1396.             SetPort (wm_curWindow);
  1397.             CopyRgn (wm_curWindow->visRgn, wm_visRgn);
  1398.             X_Ray_LocalToGlobalRgn (wm_visRgn);
  1399.             SectRgn (wm_visRgn, wm_transVisRgn, wm_visRgn);
  1400.             X_Ray_GlobalToLocalRgn (wm_visRgn);
  1401.             InvalRgn (wm_visRgn); // force window updates that globally intersect wm_visRgn
  1402.         }
  1403.         
  1404.         wm_curWindow = (WindowPtr)((WindowPeek)wm_curWindow)->nextWindow;
  1405.     }
  1406.     
  1407.     SetEmptyRgn (wm_transVisRgn);
  1408.     SetEmptyRgn (wm_visRgn);
  1409.     SetPort (wm_curPort); // restore drawing environ
  1410.     
  1411.     X_RayDrawLevel--; // resume X_Ray
  1412. }
  1413.  
  1414.  
  1415. void AssureUpdateForTransparent (WindowPtr theWindow)
  1416. {
  1417.     // when trans windows come forward their update areas are not
  1418.     // computed correctly so help them out
  1419.     DiffRgn (theWindow->visRgn, wm_transReorderVisRgn, wm_transReorderVisRgn);
  1420.     SetPort (theWindow);
  1421.     InvalRgn (wm_transReorderVisRgn);
  1422.     
  1423.     SetEmptyRgn (wm_transReorderVisRgn);
  1424. }
  1425.